
import {
    RESEIVE_ADDRESS,
    RESEIVE_FOODSTYPES,
    RESEIVE_SHOPS,
    RESEIVE_INFO,
    RESEIVE_RATINGS,
    RESEIVE_GOODS
} from './mutation-types.js'
import { reqAddress, reqFoodsTypes, reqShoplist, reqShopGoods, reqShopRatings, reqShopInfo} from '../api'
export default {
    //异步获取地址
    async getAddress({commit,state}){
        //发送异步请求
        const geohash = state.latitude + ',' + state.longitude
       const result = await reqAddress(geohash)
        //提交一个mutation
        if (result.code === 0){
            const address = result.data
            commit(RESEIVE_ADDRESS,{address})
        }
    },

    //异步获取商家
    async getFoodstypes({commit,state}){
        //发送异步请求
        const geohash = state.latitude + ',' + state.longitude
        const result = await reqFoodsTypes(geohash)
        //提交一个mutation
        if (result.code === 0){
            const foodstypes = result.data
            commit(RESEIVE_FOODSTYPES,{foodstypes})
        }
    },

    //异步获取经纬度
    async getShops({commit,state}){
        //发送异步请求
              const {longtitude,latitude} = state
        const result = await reqShoplist(longtitude,latitude)
        //提交一个mutation
        if (result.code === 0){
            const shops = result.data
            commit(RESEIVE_SHOPS,{shops})
        }
    },

    //异步获取商家信息
    async getShopInfo({commit}){
        //发送异步请求
        const result = await reqShopInfo()
        //提交一个mutation
        if (result.code === 0){
            const info = result.data
            commit(RESEIVE_INFO,{info})
        }
    },
/*    async getShopInfo({commit}){
        //发送异步请求
        const result = await reqShopInfo()
        //提交一个mutation
        if (result.code === 0){
            const info = result.data
            commit(RESEIVE_INFO,{info})
        }
    },*/

    //异步获取商家评价列表
    async getShopRatings({commit}){
        //发送异步请求
        const result = await reqShopRatings()
        //提交一个mutation
        if (result.code === 0){
            const ratings = result.data
            commit(RESEIVE_RATINGS,{ratings})
        }
    },
/*    async getShopRatings({commit}){
        //发送异步请求
        const result = await reqShopRatings()
        //提交一个mutation
        if (result.code === 0){
            const ratings = result.data
            commit(RESEIVE_RATINGS,{ratings})
        }
    },*/

    //异步获取商家商家列表
    async getShopGoods({commit}){
        //发送异步请求
        const result = await reqShopGoods()
        //提交一个mutation
        if (result.code === 0){
            const goods = result.data
            commit(RESEIVE_GOODS,{goods})
        }
    },
/*    async getShopGoods({commit}){
        //发送异步请求
        const result = await reqShopGoods()
        //提交一个mutation
        if (result.code === 0){
            const goods = result.data
            commit(RESEIVE_GOODS,{goods})
        }
    },*/
}